import json
import logging
from commit import sed_json
import requests

class TestZH():
    #初始化全局变量
    token1=None
    #调用setup方法
    def setup_method(self):
        print("开始进行测试")
    # 调用teardown方法
    def teardown_method(self):
        print("结束测试")
    #前置必须登录
    def test_login(self):
        try:
            url="http://10.59.9.21/api/user/login"
            data={"username":"","password":""}
            head={"content-type":"application/json"}
            r=requests.post(url=url,json=data,headers=head)
            print(r.json())
            TestZH.token1 = r.json()['data']['token']
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
    #1.正例
    def test_xinzeng1(self):
        try:
            url="http://10.59.9.21//api/user/register"
            data={"username":"wadd23323wadaw","password":"+NParMl8hnIwJtGfrwAEaQu+UgLUZ28IJggmPy887Ys=","checkPwd":"+NParMl8hnIwJtGfrwAEaQu+UgLUZ28IJggmPy887Ys=","a_id":"bei23jing","dtype":2,"phone":"18519890185","deadline":"2025-12-30"}
            head={"uid":"1","token":TestZH.token1,"content-type":"application/json"}
            r = requests.post(url=url, json=data, headers=head)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)

    #2.删除接口的username参数，正常填写其他参数，新增代理商失败
    def test_xinzeng2(self):
        try:
            url = "http://10.59.9.21//api/user/register"
            data = {"username":"wad","password":"+NParMl8hnIwJtGfrwAEaQu+UgLUZ28IJggmPy887Ys=","checkPwd":"+NParMl8hnIwJtGfrwAEaQu+UgLUZ28IJggmPy887Ys=","a_id":"beijing","dtype":2,"phone":"18519890185","deadline":"2025-12-30"}
            head = {"uid": "1", "token": TestZH.token1, "content-type": "application/json"}
            r = requests.post(url=url, json=data, headers=head)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
        assert "'code':1" not in r.text

    # 3.输入小于8位的密码参数，正常填写其他参数，新增代理商失败
    def test_xinzeng3(self):
        try:
            url = "http://10.59.9.21//api/user/register"
            data = {"username": "wad", "password": "+NParMl8hnIwJtGfrwAEaQu+UgLUZ28IJggmPy887Ys=",
                     "checkPwd": "+NParMl8hnIwJtGfrwAEaQu+UgLUZ28IJggmPy887Ys=", "a_id": "beijing", "dtype": 2,
                     "phone": "18519890185", "deadline": "2025-12-30"}
            head = {"uid": "1", "token": TestZH.token1, "content-type": "application/json"}
            r = requests.post(url=url, json=data, headers=head)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
        assert "'code':1" not in r.text

    # 4.不输入用户名参数，正常填写其他参数，新增代理商失败
    def test_xinzeng4(self):
        try:
            url = "http://10.59.9.21//api/user/register"
            data = {"username":"","password":"+NParMl8hnIwJtGfrwAEaQu+UgLUZ28IJggmPy887Ys=","checkPwd":"+NParMl8hnIwJtGfrwAEaQu+UgLUZ28IJggmPy887Ys=","a_id":"beijing","dtype":2,"phone":"18519890185","deadline":"2025-12-30"}
            head = {"uid": "1", "token": TestZH.token1, "content-type": "application/json"}
            r = requests.post(url=url, json=data, headers=head)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
        assert "'code':1" not in r.text

    # 5.不输入密码参数，正常填写其他参数，新增代理商失败
    def test_xinzeng5(self):
        try:
            url = "http://10.59.9.21//api/user/register"
            data = {"username":"adminqweq","password":"","checkPwd":"+NParMl8hnIwJtGfrwAEaQu+UgLUZ28IJggmPy887Ys=","a_id":"beijing","dtype":2,"phone":"18519890185","deadline":"2025-12-30"}
            head = {"uid": "1", "token": TestZH.token1, "content-type": "application/json"}
            r = requests.post(url=url, json=data, headers=head)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)
        assert "'code':1" not in r.text